#!/bin/sh

# debian
if [ ! -d usr/share/terminfo/x ] ; then
	rm -rf usr/share/terminfo
	ln -s ../../lib/terminfo usr/share/terminfo
	ln -s ../../lib/terminfo usr/lib/terminfo
# slackware
elif [ ! -d lib/terminfo/x ] ; then
	rm -rf lib/terminfo
	mkdir -p lib usr/lib
	ln -s ../usr/share/terminfo lib/terminfo
	ln -s ../../usr/share/terminfo usr/lib/terminfo
fi

#===================================================

# + debian ncurses-base
list2='ansi
cons25
cons25-debian
cygwin
dumb
Eterm
hurd
linux
linux-c
linux-c-nc
linux-koi8
linux-koi8r
linux-lat
linux-m
linux-nic
mach
mach-bold
mach-color
mach-gnu
mach-gnu-color
pcansi
rxvt
rxvt-basic
rxvt-unicode
rxvt-xpm
rxvt-color
screen
screen-256color
screen-256color-bce
screen-bce
screen-s
screen-w
sun
vt100
vt102
vt125
vt131
vt132
vt200
vt220
vt320
vt340
vt400
vt420
vt520
vt525
vt61
vt52
vte
wsvt25
wsvt25m
xterm
xterm-256color
xterm-color
xterm-mono
xterm-new
xterm-nic
xterm-nrc
xterm-r5
xterm-r6
xterm-redhat
xterm-rep
xterms
xterms-sun
xterm-sun
xterm-vi
xterm-vt220
xterm-xfree86'

(
	find usr/share/terminfo -mindepth 1 -type f | \
	while read i ;do
		case $list2 in
			*"${i##*/}"*) continue ;; #ok
			*) echo -n "$i " ;;
		esac
	done
) > /tmp/zzzz$$_$$
rm -f $(cat /tmp/zzzz$$_$$)
rm -f /tmp/zzzz$$_$$

# delete invalid symlinks
find -L usr/share/terminfo -type l -delete

rmdir $(find usr/share/terminfo -mindepth 1 -type d) 2>/dev/null

# slacko
if [ -f usr/share/terminfo/r/rxvt -a ! -e usr/share/terminfo/r/rxvt-unicode ] ; then
	ln -snfv rxvt usr/share/terminfo/r/rxvt-unicode
fi

### END ###
